package org.hk.kg.utils;

import java.io.IOException;
import java.io.InputStream;

import org.hk.kg.exception.EleParserException;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class XMLUtils {
	private static SAXBuilder builder = new SAXBuilder();
	public static Document getDocument(InputStream ips) throws EleParserException
	{
		try {
			return builder.build(ips);
		} catch (JDOMException e) {
			throw new EleParserException();
		} catch (IOException e) {
			throw new EleParserException();
		}
		finally
		{
			try {
				ips.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static Element getElementFromDoc(Document doc,String elementName)
	{
		return doc.getRootElement().getChild(elementName);
	}
}
